package com.example.demo.service;

import com.example.demo.entity.PositionEntity;
import com.example.demo.mapper.PositionMapper;
import com.example.demo.mapper.UserMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

@Service
public class PersonalService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    PositionMapper positionMapper;


    public Set<PositionEntity> findSharePositionByUserId(String userId) {
        List<String> positionIds = userMapper.findSharePositionId(userId);
        Set<PositionEntity> positionEntities = new HashSet<>();
        for (String positionId : positionIds) {
            PositionEntity positionEntity = positionMapper.findSharePositionById(positionId);
            positionEntities.add(positionEntity);
        }
        return positionEntities;

    }

    public void insertSharePosition(String positionId, String userId) {
        String id = UUID.randomUUID().toString();
        userMapper.insertSharePosition(id, positionId, userId);
    }
}
